import {reqGoodsListInfo} from '@/api'



//储存数据的地方
const state = {
    goodsListInfo:{}
} 

 //直接修改数据的地方 不能用if for 不能异步
const mutations = {
REACTIVE_GOODSLISTINFO(state,goodsListInfo){
    state.goodsListInfo = goodsListInfo
}
}

//1、用来和vue组件打交道，vue组件会dispatch action当中的函数
//2、action是用来通知mutation，去修改state的数据
const actions = {
    async getGoodsListInfo({commit},searchParams){
        const result = await reqGoodsListInfo(searchParams)
            if (result.code === 200) {
                commit('REACTIVE_GOODSLISTINFO',result.data)
                
            
        }
    }
}

//简化数据操作的
const getters = {
    attrsList(state){
        return state.goodsListInfo.attrsList || []
      },
      goodsList(state){
        return state.goodsListInfo.goodsList || []
      },
      trademarkList(state){
        return state.goodsListInfo.trademarkList || []
      }
} 


//第三步 向外暴露一个store对象
export default({
    state,
    mutations,
    actions,
    getters

})
//第四步 